 function whenDocumentReady(){
	 if($("input#top_user_login_tag").length>0){
			if($("#user_type_flag").val()==1){
				ajax4ValPulishGoods();
			}
		}
	//弹出发送邀请
	$('.cd-popup-trigger-study').on('click', function(event){
        if(!setCurrentLine($(this))){
            return false;
        }
        event.preventDefault();
		$.ajax({
			type:"post",
			url:_appRoot+"/userCenter/getUpStatusGoodsList",
			dataType:"json",
			success: function(data){
				if(data.result==1){
					var list = data.goodsList;
					var optionHtml="";
					for(var i=0;i<list.length;i++){
						optionHtml+="<option data='"+list[i].goodsId+"' dataindex='"+list[i].notes+"'>"+list[i].goodsName+"</option>";
					}
					$("#class_address").val(list[0].notes);
					$("#courseSelect").html(optionHtml);
					$('#cd-popup-study').fadeIn(300);
					$('#cd-popup-study .cd-popup-container').fadeIn(300);
				}
				else{
					clickautohide(data.message,3);
				}
			}
		});

		var invication = $("#hiddenInvication");
		var cookieLoginTime=getCookie("lastLoginTime");
		var lastLoginTime=$("#lastLoginTime").val();
		if(cookieLoginTime==lastLoginTime){
			var courseText=getCookie("lastCourseText");
				if(courseText!=null && courseText!=""){
				$("#zmd_h").val(courseText);
			}
		}else{
			$("#zmd_h").val("");
		}
		//$("#zmd_h").val($(invication).find("#content").val());
		//$("#goods_name").val($(invication).find("#goodsName").val());
		//$("#goods_url").val($(invication).find("#goodsUrl").val());
		//$("#class_address").val($(invication).find("#address").val());
		$("#teacher_name").val($(invication).find("#teacherName").val());
		$("#teacher_phone").val($(invication).find("#phone").val());
		if(($("#text_tip").length>0)&&($("#zmd_h").val()=="")){
			$("#text_tip").show();
		}
		else if($("#text_tip").length>0){
			$("#text_tip").hide();
		}/*ie789*/
		var invitationSwtich = $("#invitationSwtich").val();
		if(invitationSwtich==1){
			$("#open_auto").attr("checked",true);
		}else{
			$("#close_auto").attr("checked",true);
		}
		$("#send_button").removeAttr("disabled","disabled");
		countChar('.zmd_h',200,'.yi_yy');
    });
    //点击x关闭
    $('#cd-popup-study').on('click', function(event){
        if( $(event.target).is('.closebtn2') || $(event.target).is('#cd-popup-study') || $(event.target).is('#boxCancel2')) {
            event.preventDefault();
            $(this).fadeOut(300);
            $('#cd-popup-study .cd-popup-container').fadeOut(300);
			$("#yi_yy").text(0);
        }
    });
    //按esc关闭
    $(document).keyup(function(event){
        if(event.which=='27'){
            $('#cd-popup-study').fadeOut(300);
            $('#cd-popup-study .cd-popup-container').fadeOut(300);
			$("#yi_yy").text(0);
        }
    });
	//弹出加入求学
    $('.cd-popup-trigger-studyjoin').on('click', function(event){
        if(!setCurrentLine($(this))){
            return false;
        }
        event.preventDefault();
        $('#cd-popup-studyjoin').fadeIn(300);
        $('#cd-popup-studyjoin .cd-popup-container').fadeIn(300);
        $('#cd-popup-studyjoin').find("input:text,textarea").val("");
		
		$("#text_box").val($("#botton_people").val());
		$(".qiu_username").val($("#botton_name").val());
		$(".qiu_userphone").val($("#botton_phone").val());
		$(".qiu_email").val($("#botton_email").val());
		if(($("#email_tip").length>0)&&($(".qiu_email").val()=="")){
			$("#email_tip").show();
		}
		else if($("#email_tip").length>0){
			$("#email_tip").hide();
		}/*ie789*/
		$(".qiu_time").val($("#botton_contactTime").val());
    });
    //点击关闭
    $('#cd-popup-studyjoin').on('click', function(event){
        if( $(event.target).is('.closebtn1') || $(event.target).is('#cd-popup-studyjoin') || $(event.target).is('#boxCancel1')||$(event.target).is('#jia_no') ) {
            event.preventDefault();
            $(this).fadeOut(300);
            $('#cd-popup-studyjoin .cd-popup-container').fadeOut(300);
			$("#adddiv input").remove();
			$(".dele_btu").remove();
        }
    });
    //close popup when clicking the esc keyboard button
    $(document).keyup(function(event){
        if(event.which=='27'){
            $('#cd-popup-studyjoin').fadeOut(300);
            $('#cd-popup-studyjoin .cd-popup-container').fadeOut(300);
			$("#adddiv input").remove();
			$(".dele_btu").remove();
        }
    });
	$(function(){
        var t = $("#text_box");
        $("#add").click(function(){        
            t.val(parseInt(t.val())+1)
        })
        $("#min").click(function(){
            t.val(parseInt(t.val())-1)
        })
    })
 }
 //统计邮件输入框文本字数
	function countChar(textareaID,maxNum,spanID){
		var NowNum=$(textareaID).val().length;
		if(NowNum>maxNum){
			$(textareaID).val($(textareaID).val().substr(0,maxNum));
		}
		else{
			$(spanID).text(NowNum);	
		}
	}
    //添加邮箱
    function addemail(){ 
	 var email_num=$(".qiu_emails").length;
     if(email_num<=9){
     var obj = document.getElementById("adddiv");
         obj.insertAdjacentHTML("afterBegin","<input class='qiu_emails emails' type='text'/><a class='dele_btu' onclick='deleteEmail(this)'>-删除</a>");
         //$(".qiu_emails").attr("value","邮箱"+email_num);
     }
     else alert("最多输入10个邮箱!");
    }
	//删除邮箱
	function deleteEmail(a){
		$(a).prev().remove();
		$(a).remove();
	}
	//选择开启还是关闭自动邀请
	function chooseOne(cb){      
         var obj = document.getElementsByName("yq_check");   
         for (i=0; i<obj.length; i++){    
             if (obj[i]!=cb) 
			 obj[i].checked = false;
             else obj[i].checked = true; 		 
         }
	} 
	function changeCourse(){
		$("#class_address").val($("#courseSelect option:selected").attr("dataIndex"));
	}
	//提交加入求学数据
	function joinStudy(){
		var studyId=$("#study_id").val();
		if(!checkData(studyId,0,'lt')){
			clickautohide("数据异常，请刷新页面!",3);
			return ;
		}
		var peopleCount=$("#text_box").val();
		if(!checkInt(peopleCount,1,'gt')){
			clickautohide("请输入正确的求学人数!",3);
			return ;
		}
		
		var name=$(".qiu_username").val();
		if(!checkData(name,1,'lt')){
			clickautohide("请输入正确的联系人姓名",3);
			return ;
		}
		var phone=$(".qiu_userphone").val();
		if(!checkMobile(phone) && !checkPhone(phone)){
			clickautohide("请输入正确的联系方式",3);
			return ;
		}
		
		//邮箱
		var email=$(".emails");
		var emails="";
		for(var i=0;i<email.length;i++){
			if(email[i].value==""){
				break;
			}
			if(checkEmail(email[i].value)){
			emails=emails+email[i].value+",";
			}
			else{ clickautohide("邮箱格式不正确",3);return ;}
		}
		if(emails.length<=0){
			clickautohide("请输入正确的邮箱",3);
			return ;
		}
		var index=emails.lastIndexOf(",");
		emails=emails.substring(0,index);
		
		var contactTime=$(".qiu_time").val();
		
		
		$.ajax({
			type:"POST",
			url:"/userCenter/joinStudyApply",
			data:{id:studyId,peopleCount:peopleCount,name:name,phone:phone,email:emails,contactTime:contactTime},
			dataType:"json",
			success: function(data){
				if(data.result==1){
					clickautohide("加入成功",2);
					$("#botton_people").val(peopleCount);
					$("#botton_name").val(name);
					$("#botton_phone").val(phone);
					$("#botton_contactTime").val(contactTime);
					closePopup('-studyjoin');
				}else{
					clickautohide("加入失败:"+data.message,3);
				}
			}
		});
	}
	//发送邀请	
	function sendInvite(){
		setCookie("lastCourseText",$("#zmd_h").val());
		setCookie("lastLoginTime",$("#lastLoginTime").val());
		var studyId=$("#send_stu_id").val();
		if(!checkData(studyId,0,'lt')){
			clickautohide("数据异常，请刷新页面!",3);
			return ;
		}
		var content=$("#zmd_h").val();
		if(content==""){
			content="您好！经查看您发布的求学信息，我有一个课程班级与您的期望较为符合，特邀请您查看我的课程信息。只需点击“接受邀请”，即可进入查看课程。";
		}
		else if(!checkData(content,10,'lt')){
			clickautohide("求学邀请正文不得少于10个字符!",3);
			return ;
		}
		var goodsName=$("#courseSelect option:selected").text();
		/*var goodsName=$("#goods_name").val();
		if(!checkData(goodsName,3,'lt')){
			clickautohide("请输入正确的商品名称!",3);
			return ;
		}*/
		var goodsUrl="http://www.yxit.net/browse/queryGoods/"+$("#courseSelect option:selected").attr("data");
		/*var goodsUrl=$("#goods_url").val();
		if(!checkData(goodsUrl,20,'lt')){
			clickautohide("请输入正确的商品链接!",3);
			return ;
		}*/

		var address=$("#class_address").val();
		if(!checkData(address,1,'lt')){
			clickautohide("请输入正确的上课地址!",3);
			return ;
		}
		var teacherName=$("#teacher_name").val();
		if(!checkData(teacherName,1,'lt')){
			clickautohide("请输入正确的授课讲师姓名",3);
			return ;
		}
		var phone=$("#teacher_phone").val();
		if(!checkMobile(phone) && !checkPhone(phone)){
			clickautohide("请输入正确的联系方式",3);
			return ;
		}
		var isAuto;
			if($("#open_auto").is(":checked")){
				isAuto=1;
			}
			else{
				isAuto=0;
			}
		$("#send_button").attr("disabled","disabled");
		$.ajax({
			type:"POST",
			url:"/userCenter/sendInvitation",
			async:false,
			data:{contactIds:studyId,content:content,goodsName:goodsName,goodsUrl:goodsUrl,address:address,teacherName:teacherName,phone:phone,isAuto:isAuto},
			dataType:"json",
			success: function(data){
				if(data.result==1){
					clickautohide("发送邀请成功",2);
					var invication = $("#hiddenInvication");
					$(invication).find("#content").val(content);
					$(invication).find("#goodsName").val(goodsName);
					$(invication).find("#goodsUrl").val(goodsUrl);
					$(invication).find("#address").val(address);
					$(invication).find("#teacherName").val(teacherName);
					$(invication).find("#phone").val(phone);
					$("#invitationSwtich").val(isAuto);
					closePopup('-study');
				}else{
					clickautohide("发送邀请失败:"+data.message,3);
				}
			}
		});
		$("#send_button").removeAttr("disabled","disabled");
		
	}
	function closePopup(target){
		$('#cd-popup'+target).fadeOut(300);
		$('#cd-popup'+target+' .cd-popup-container').fadeOut(300);
		$("#yi_yy").text(0);
	}
	
	
	function toPublicGoods(){
		$(".to_go_to").html("<a href='http://www.yxit.net/js/"+_appRoot+"/userCenter/categorySelect.html'>我要去发布课程>></a>");
		$(".tip_p").html("<span></span>您已是讲师，请先在讲师中心后台发布课程，复制该课程链接，才能发送开课邀请。");
		getTipDiv();
	}
	
	function toBeTeacher(){
		$(".to_go_to").html("<a href='http://www.yxit.net/js/"+_appRoot+"/userCenter/teacherApply.html'>我要申请成为讲师>></a>");
		$(".tip_p").html("<span></span>您还不是讲师，请先申请成为讲师，然后在讲师中心后台发布课程，复制该课程链接，才能发送开课邀请。");
		getTipDiv();
	}
	function getTipDiv(){
		$("#tea_tip_back").fadeIn(300);
        $("#tea_tip").fadeIn(300);	
		$("#tea_tip_back").on('click', function(event){
        if( $(event.target).is('.close_tea_tip') || $(event.target).is('#tea_tip_back') || $(event.target).is('.close_tip_but')) {
            event.preventDefault();
            $(this).fadeOut(300);
            $("#tea_tip").fadeOut(300);
        }
		});
		$(document).keyup(function(event){
        if(event.which=='27'){
            $("#tea_tip_back").fadeOut(300);
            $("#tea_tip").fadeOut(300);
        }
		});
	}
	
	//查询讲师是否发布过商品
	function ajax4ValPulishGoods(){
		$.ajax({
			type:"POST",
			url:"/userCenter/ajax4ValPulishGoods",
			dataType:"json",
			success: function(data){
				if(data.result==1){
					if(data.flag==1){
					}else{
						$("#f_s_btu").removeClass().unbind("click").attr("onclick","toPublicGoods();");
					}
				}
			}
		});
	}